package com.lebo.portal.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lebo.portal.repository.ActivityMapper;
import com.lebo.portal.view.PageQuery;
import com.lebo.portal.view.PageResult;
import com.lebo.web.domain.Activity;

@Service
public class ActivityService extends BaseService {
    @Autowired
    private ActivityMapper activityMapper;

    public PageResult<List<Activity>> pagingActivities(PageQuery<Activity> pageQuery) {
        Integer categoryId = null != pageQuery.getFilter() ? pageQuery.getFilter().getCategoryId() : null;
        List<Activity> acts = activityMapper.getActivitys(categoryId, pageQuery.getPageInfo().getCurrPage(),
                pageQuery.getPageInfo().getPageSize());

        Long totalItem = activityMapper.getTotalItem(categoryId);
        return this.processResult(acts, pageQuery, totalItem);
    }

    public Activity findSingleActivity(long id) throws Exception {
        return activityMapper.<Long>getDetailsBytId(id);
    }
}
